package 网络.TCP;

import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

import static java.net.InetAddress.getLocalHost;

public class SocketTCP01Client {
    public static void main(String[] args) throws Exception {
        //连接服务端(ip , 端口)
        ///连接本机的9999端口，如果连接成功，返回Socket对象
        Socket socket = new Socket(InetAddress.getLocalHost(),9999);
        System.out.println("客户端 socket返回=" + socket.getClass());
        //连接后，生成Socket，通过socket.getOutPutStream(),得到和socket对象关联的输出流对象
        OutputStream outputStream = socket.getOutputStream();
        //通过输出流，写入数据到数据通道
        outputStream.write("hell world".getBytes());
        //关闭流
        outputStream.close();
        //关闭socket
        socket.close();
        System.out.println("客户端退出");
    }
}
